﻿using System;
using System.Drawing;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Defines an HTML column group for a table.
    /// </summary>
    [Serializable]
    public class ColGroup : Element {
        private CellHorizontalAlignment? _align;
        private Color? _bgcolor;
        private char? _char;
        private int? _charoff;
        private int? _span;
        private CellVerticalAlignment? _valign;
        private string _width;

        /// <summary>
        /// Gets or sets the horizontal alignment of the column.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public CellHorizontalAlignment? Align {
            get { return _align; }
            set { _align = value; }
        }

        /// <summary>
        /// Gets or sets the background color of the column.
        /// </summary>
        [Obsolete("Non-standard - use CSS instead.")]
        public Color? BGColor {
            get { return _bgcolor; }
            set { _bgcolor = value; }
        }

        /// <summary>
        /// Sets the character to align cells in a column on.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public char? Char {
            get { return _char; }
            set { _char = value; }
        }

        /// <summary>
        /// Gets the offset number of characters from char to align a column
        /// on.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public int? CharOff {
            get { return _charoff; }
            set {
                if (value == null || value > 0) {
                    _charoff = value;
                } else {
                    throw new ArgumentException(
                        "CharOff must be greater than zero.", "value");
                }
            }
        }

        /// <summary>
        /// Determines the number of consecutive columns this col spans.
        /// </summary>
        public int? Span {
            get { return _span; }
            set {
                if (value == null || value > 0) {
                    _span = value;
                } else {
                    throw new ArgumentException(
                        "Span must be greater than zero.", "value");
                }
            }
        }

        /// <summary>
        /// Gets or sets the vertical alignment of this column.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public CellVerticalAlignment? VAlign {
            get { return _valign; }
            set { _valign = value; }
        }

        /// <summary>
        /// Gets or sets the width of this column.
        /// </summary>
        /// <remarks>This is a string, and not an integer, because the *
        /// character can be appended to the end to make width operation
        /// content-aware.</remarks>
        [Obsolete("Deprecated in HTML5 - use CSS instead.")]
        public string Width {
            get { return _width; }
            set { _width = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _align, "align", true);
            AttributeWriter.Write(sb, _bgcolor, "bgcolor");
            AttributeWriter.Write(sb, _char, "char");
            AttributeWriter.Write(sb, _charoff, "charoff");
            AttributeWriter.Write(sb, _span, "span");
            AttributeWriter.Write(sb, _valign, "valign", true);
            AttributeWriter.Write(sb, _width, "width");
        }
    }
}
